home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / SAT / myPlatform ƒ / myPlatform.p < prev    next >
Encoding:
Text File  |  1993-06-25  |  2.6 KB  |  87 lines  |  [TEXT/PJMM]

  1. {***************************}
  2. {********* myPlatform **********}
  3. {***************************}
  4.  
  5. {This demo is a hack I made, testing if we can use faceless sprites to make stationary}
  6. {obstacles. That worked pretty nicely, so I went on and made some moving platforms too.}
  7. {Take it for what it is: a test hack that suggests one way to make this kind of games.}
  8. {There are many other ways. The controls can be improved a lot, but it is a start.}
  9.  
  10. program myPlatform;
  11.  
  12.     uses
  13.         SAT, sPlayerSprite, sPlatform, sMovPlatForm, sHMovPlatForm;
  14.  
  15.     var
  16.         gameWind: WindowPtr;
  17.         ignoreSp: SpritePtr;
  18.         l: longint;
  19.         p: Point;
  20.     var
  21.         thepat: SATPatHandle;
  22.  
  23.     procedure DrawInfo;
  24.         var
  25.             r: Rect;
  26.     begin
  27.         SetPort(BackScreen);
  28.         SetRect(r, 100, 50, 300, 100);
  29.         EraseRect(r);
  30.         FrameRect(r);
  31.         MoveTo(110, 70);
  32.         DrawString('SAT Platform demo');
  33.         MoveTo(110, 90);
  34.         DrawString('Move with "," "." and space');
  35.         SATBackChanged(r);
  36.     end;
  37.  
  38. begin
  39. {Standard Inits are done by Think Pascal.}
  40.  
  41.     ConfigureSAT(true, layerSort, BackwardCollision, 32);
  42.     gameWind := InitSAT(0, 0, 512, 322); {No PICTs}
  43.  
  44. {Use a background pattern (instead of PICTs - just to demo that too)}
  45.     setport(backscreen);
  46.     thepat := SATGetPat(128);
  47.     SATPenPat(thepat);
  48.     PaintRect(0, 0, offsizev, offsizeh);
  49. {The following CopyBits would have been faster if we had used SATSetPortBackScreen}
  50.     CopyBits(BackScreen^.portbits, offscreen^.portbits, offscreen^.portrect, offscreen^.portrect, srcCopy, nil);
  51.  
  52.     DrawInfo;
  53.  
  54. {Initialize all sprite units}
  55.     initPlayerSprite;
  56.     initPlatform;
  57.     initMovPlatform;
  58.     initHMovPlatform;
  59.  
  60. {Show the game window and update it. (SATwind and gameWind are the same.)}
  61.     ShowWindow(gameWind);
  62.     SelectWindow(gameWind);
  63.     PeekOffscreen;
  64.  
  65. {Make the sprites.}
  66.     GetMouse(p);
  67.     ignoreSp := NewSprite(1, p.h, p.v, @HandlePlayerSprite, @SetupPlayerSprite, @HitPlayerSprite);
  68.     ignoreSp := NewSprite(0, 50, 300, @HandlePlatform, @SetupPlatform, @HitPlatform);
  69.     ignoreSp := NewSprite(0, 150, 200, @HandlePlatform, @SetupPlatform, @HitPlatform);
  70.     ignoreSp := NewSprite(0, 250, 100, @HandlePlatform, @SetupPlatform, @HitPlatform);
  71.     ignoreSp := NewSprite(0, 350, 50, @HandlePlatform, @SetupPlatform, @HitPlatform);
  72.  
  73.     ignoreSp := NewSprite(0, 350, 300, @HandleMovPlatform, @SetupMovPlatform, @HitMovPlatform);
  74.     ignoreSp := NewSprite(0, 50, 200, @HandleMovPlatform, @SetupMovPlatform, @HitMovPlatform);
  75.  
  76.     ignoreSp := NewSprite(0, 200, 150, @HandleHMovPlatform, @SetupHMovPlatform, @HitHMovPlatform);
  77.  
  78.     HideCursor;
  79.     repeat
  80.         l := TickCount;
  81.         RunSAT(true); {Run one frame of animation.}
  82.         while l > TickCount - 2 do {Maximize speed to 30 fps}
  83.             ;
  84.     until Button;
  85.     ShowCursor;
  86.     SATSoundShutUp; {Always make sure the sound channel is de-allocated!}
  87. end.